package cn.dankal.lequ.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.dankal.lequ.R;
import cn.dankal.lequ.commom.adapter.FragmentAdapter;
import cn.dankal.lequ.commom.util.Constant;
import cn.dankal.lequ.ui.fragment.buluo_fragment.GonglveFragment;
import cn.dankal.lequ.ui.fragment.buluo_fragment.HuatiFragment;
import cn.dankal.lequ.ui.fragment.buluo_fragment.QunzuFragment;
import cn.dankal.lequ.ui.fragment.buluo_fragment.RemenFragment;
import cn.dankal.lequ.ui.fragment.buluo_fragment.ShipinFragment;
import cn.dankal.lequ.ui.fragment.buluo_fragment.WendaFragment;

/**
 * Created by Dankal on 16/4/26.
 */
public class BuLuoActivity extends AppCompatActivity {


    @Bind(R.id.view_pager)
    ViewPager view_pager;
    @Bind(R.id.tab_layout)
    TabLayout tab_layout;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buluo);
        ButterKnife.bind(this);
        initTabLayout();
    }


    private void initTabLayout() {
        List<Fragment> fragments = new ArrayList<>();
        ArrayList<String> tablayout_titles = new ArrayList<>();
        tablayout_titles.add(Constant.HUATI);
        fragments.add(new HuatiFragment());
        tablayout_titles.add(Constant.REMEN);
        fragments.add(new RemenFragment());
        tablayout_titles.add(Constant.WENDA);
        fragments.add(new WendaFragment());
        tablayout_titles.add(Constant.SHIPIN);
        fragments.add(new ShipinFragment());
        tablayout_titles.add(Constant.GONGLVE);
        fragments.add(new GonglveFragment());
        tablayout_titles.add(Constant.QUNLZU);
        fragments.add(new QunzuFragment());
        for (int i = 0; i < tablayout_titles.size(); i++) {
            tab_layout.addTab(tab_layout.newTab().setText(tablayout_titles.get(i)));
        }
        FragmentAdapter adapter = new FragmentAdapter(BuLuoActivity.this.getSupportFragmentManager(), fragments, tablayout_titles);
        view_pager.setAdapter(adapter);
        tab_layout.setupWithViewPager(view_pager);
        tab_layout.setTabsFromPagerAdapter(adapter);
    }

    @OnClick({R.id.bt_back})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.bt_back:
                this.finish();
                break;

        }
    }
}
